
import { createStoreBindings } from "mobx-miniprogram-bindings"
import store from "../../store/piece"
Page({
  /**
  * 生命周期函数--监听页面显示
  */
  onShow: function () {
  if (typeof this.getTabBar === 'function' &&
    this.getTabBar()) {
    this.getTabBar().setData({
      selected: 1
    })
  }
},
  data: {
    logs: [],
    sphIndex:null,
    sphArray:['-10.0','-9.75','-9.5','-9.25','-9.0','-8.75','-8.5','-8.25','-8.0','-7.75','-7.5','-7.25','-7.0','-6.75','-6.5','-6.25','-6.0','-5.75','-5.5','-5.25','-5.0','-4.75','-4.5','-4.25','-4.0','-3.75','-3.5','-3.25','-3.0','-2.75','-2.5','-2.25','-2.0','-1.75','-1.5','-1.25','-1.0','-0.75','-0.5','-0.25','0','0.25','0.5','0.75','1.0','1.25','1.5','1.75','2.0','2.25','2.5','2.75','3.0','3.25','3.5','3.75','4.0','4.25','4.5','4.75','5.0','5.25','5.5','5.75','6.0','6.25','6.5','6.75','7.0','7.25','7.5','7.75','8.0','8.25','8.5','8.75','9.0','9.25','9.5','9.75','10.0'],
    cylArray:['-2.5','-2.25','-2.00','-1.75','-1.50','-1.25','-1.00','-0.75','-0.50','-0.25','0.25','0.50','0.75','1.00','1.25','1.50','1.75','2.00','2.25','2.50'],
    cylIndex:null,
    axisIndex:null,
    axisIndexArray:[],

    sphLeftIndex:null,
    cylLeftIndex:null,
    axisLeftIndex:null,
    axisLeftArray:[],
    cylLeftArray:['-2.5','-2.25','-2.00','-1.75','-1.50','-1.25','-1.00','-0.75','-0.50','-0.25','0.25','0.50','0.75','1.00','1.25','1.50','1.75','2.00','2.25','2.50'],
    sphLeftArray:['-10.0','-9.75','-9.5','-9.25','-9.0','-8.75','-8.5','-8.25','-8.0','-7.75','-7.5','-7.25','-7.0','-6.75','-6.5','-6.25','-6.0','-5.75','-5.5','-5.25','-5.0','-4.75','-4.5','-4.25','-4.0','-3.75','-3.5','-3.25','-3.0','-2.75','-2.5','-2.25','-2.0','-1.75','-1.5','-1.25','-1.0','-0.75','-0.5','-0.25','0','0.25','0.5','0.75','1.0','1.25','1.5','1.75','2.0','2.25','2.5','2.75','3.0','3.25','3.5','3.75','4.0','4.25','4.5','4.75','5.0','5.25','5.5','5.75','6.0','6.25','6.5','6.75','7.0','7.25','7.5','7.75','8.0','8.25','8.5','8.75','9.0','9.25','9.5','9.75','10.0'],

    //瞳距
    pdType:"1",
    frameType:"0",

    remark:"",
    pd:"",
    jjp:false,
    jjpArray:[
      "11mm",
      '12mm',
      '13mm',
      '14mm',
      '15mm'
    ],
    jjpIndex:null,
    lj:"",
    addList:[
      '-0.75',
      '-0.50',
      '-0.25',
      '0.00',
      '0.25',
      '0.50',
      '0.75',
      '1.00',
      '1.25',
      '1.50',
      '1.75',
      '2.00',
      '2.25',
      '2.50',
      '2.75',
      '3.00',
      '3.25',
      '3.50'
    ],
    leftAddIndex:null,
    rightAddIndex:null



  },
  onLoad() {
    let axisIndexArray = []
      for (let index = 0; index < 181; index++) {
        axisIndexArray.push(index)
      }
      this.setData({
        axisIndexArray:axisIndexArray,
        axisLeftArray:axisIndexArray
      })

    this.storeBindings =  createStoreBindings(this, {
        store,
        fields:[
         'formData'
        ],
        actions: { updateFormDataAction: "updateFormDataAction" }
      })
  },
  onUnload() {
    // 解绑
    this.storeBindings.destroyStoreBindings()
  },
  nextBtn() {
    let data = {
      right:{
        sph:this.data.sphArray[this.data.sphIndex],
        cyl:this.data.cylArray[this.data.cylIndex],
        add:this.data.addList[this.data.rightAddIndex]
      },
      left:{
        sph:this.data.sphLeftArray[this.data.sphLeftIndex],
        cyl:this.data.cylLeftArray[this.data.cylLeftIndex],
        add:this.data.addList[this.data.leftAddIndex]
      },
      //通道长度
      jjpLength:this.data.jjpArray[this.data.jjpIndex],
      jjp:this.data.jjp?1:null,
      lj:this.data.lj
    }
    console.log("this.data------->",this.data)
    // pieceApi.prodSearch(JSON.stringify(data)).then(()=>{

    // })
    let frameTypeObj = {
      "1":"半框",
      "2":"无框",
      "0":"全框",
    }

    let toData = {
      formData:data,
      pdType:this.data.pdType,
      frameType:this.data.frameType,
      frameTypeValue:frameTypeObj[this.data.frameType],
      remark:this.data.remark,
      axisRight:this.data.axisIndexArray[this.data.axisIndex],
      axisLeft:this.data.axisLeftArray[this.data.axisLeftIndex],
      pd:this.data.pdm,
      pdTitle:this.data.pdType === '2'?this.data.pd:'',
      rightSph:this.data.sphArray[this.data.sphIndex],
      rightCyl:this.data.cylArray[this.data.cylIndex],
      leftSph:this.data.sphLeftArray[this.data.sphLeftIndex],
      leftCyl:this.data.cylLeftArray[this.data.cylLeftIndex],
      


    }
    this.updateFormDataAction(toData)
    if(this.data.jjp) {
      if(!data.right.add) {
        wx.showToast({ title: '右眼Add必传', icon: 'none' });
        return
      }

      if(!data.left.add) {
        wx.showToast({ title: '左眼Add必传', icon: 'none' });
        return
      }

      if(!data.jjpLength) {
        wx.showToast({ title: '通道长度必传', icon: 'none' });
        return
      }
      // &&!data.left.add&!data.jjpLength
      
    }
    wx.navigateTo({
      url: '../prodList/prodList?formData='+toData
    })
  },
  sphbindPickerChange(data) {
    let value = data.detail.value
    this.setData({
      sphIndex:value
    })
  },
  cylBindPickerChange(e) {
    let value = e.detail.value
    this.setData({
      cylIndex:value
    })
  },
  axisBindPickerChange(e) {
    let value = e.detail.value
    this.setData({
      axisIndex:value
    })
  },
  leftSphbindPickerChange(e) {
    let value = e.detail.value
    this.setData({
      sphLeftIndex:value
    })
  },
  leftSphbindPickerChange(e) {
    let value = e.detail.value
    this.setData({
      sphLeftIndex:value
    })
  },
  leftCylbindPickerChange(e) {
    let value = e.detail.value
    this.setData({
      cylLeftIndex:value
    })
  },
  leftAxisbindPickerChange(e) {
    let value = e.detail.value
    this.setData({
      axisLeftIndex:value
    })
  },
  onChange (e) {
  let detail =   e.detail
  this.setData({
    pdType:detail
  })
   console.log("onChange---xx--->",e)
  },
  onJjpChange(event) {
    this.setData({
      jjp: event.detail,
    });
  },
  jjpPickerChange(event) {
    console.log("jjpIndex------xx--->",event.detail)
    this.setData({
      jjpIndex: event.detail.value,
    });
  },
  leftAddPickerChange(event) {
    this.setData({
      leftAddIndex: event.detail.value,
    });
  },
  rightAddPickerChange(event) {
    this.setData({
      rightAddIndex: event.detail.value,
    });
  }
})